package cn.wolfcode.web.controller;

import cn.wolfcode.domain.SystemDictionary;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.qo.SystemDictionaryQueryObject;
import cn.wolfcode.service.ISystemDictionaryService;
import cn.wolfcode.utils.RequestPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/systemDictionary")
public class SystemDictionaryController {

    private ISystemDictionaryService systemDictionaryService;

    @Autowired
    public void setSystemDictionaryService(ISystemDictionaryService systemDictionaryService) {
        this.systemDictionaryService = systemDictionaryService;
    }

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")SystemDictionaryQueryObject qo) {
        PageInfo<SystemDictionary> pageInfo = systemDictionaryService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "systemDictionary/list";
    }


    @RequestMapping("/treeData")
    @ResponseBody
    public List<Map> treeData(){
        return systemDictionaryService.queryTreeData() ;
    }

    @RequestMapping("/queryByParentId")
    @ResponseBody
    public List<SystemDictionary> queryByParentId(Long parentId){
        return systemDictionaryService.queryByParentId(parentId) ;
    }
}
